<template>
	<div class="flexcenter ffffff">
		<div class="max_width paddingtb">
			<div class="margin_bottom3" v-for="item in tabList" :key="item.type">
				<div class="flexbetween">
					<div class="flexleft">
						<div class="leftBg margin_right1"></div>
						<div class="text_ht color_zero">{{ item.name }}</div>
					</div>
					<div class="flexleft pointer" @click="goList(item.type)">
						<div class="text_d color_nine margin_right1">查看全部</div>
						<div class="right_icon"></div>
					</div>
				</div>
				<!-- 优课 -->
				<div class="flexbetween" v-if="item.type == 1">
					<course v-for="value in item.childList" :key="value.id" :child="value"></course>
				</div>
				<!-- 辅导、资料 -->
				<div class="flexbetween flex_wrap" v-if="item.type == 2 || item.type == 4">
					<information v-for="value in item.childList" :key="value.id" :child="value"></information>
				</div>
				<!-- 测试 -->
				<div class="flexbetween flex_wrap" v-if="item.type == 3">
					<test-child v-for="value in item.childList" :key="value.id" :child="value"></test-child>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import { getHomeCourse } from "@/API/home"
	import course from "@/views/fineCourse/components/course"
	import information from "@/views/information/components/information"
	import testChild from "@/views/test/components/testChild"
	export default {
		components: {
			course,
			information,
			testChild
		},
		data() {
			return {
				tabList: [{
					type: 1,
					name: "优课",
					childList: []
				}, {
					type: 2,
					name: "辅导",
					childList: []
				}, {
					type: 3,
					name: "测试",
					childList: []
				}, {
					type: 4,
					name: "资料",
					childList: []
				}],
				cityInfo:{},//城市
				njInfo: {},//年级信息
				subjectInfo:{},//学科
			}
		},
		created() {
			let cityInfo = localStorage.getItem("cityInfo")
			if (cityInfo) {
				this.cityInfo = JSON.parse(cityInfo)
			}
			let njInfo = localStorage.getItem("njInfo")
			if (njInfo) {
				this.njInfo = JSON.parse(njInfo)
			}
			let subjectInfo = localStorage.getItem("subjectInfo")
			if (subjectInfo) {
				this.subjectInfo = JSON.parse(subjectInfo)
			}
			// this.tabList.forEach((item,index) => {
			this.getCourseList({
				// page: 1,
				// type: item.type,
				city: this.cityInfo[1],//城市id
				period: this.njInfo.period,//学段:1=小学,2=初中,3=高中,4=大学
				education_grade_id: this.njInfo.id,//年级id
				education_subject_id: this.subjectInfo[0],//学科id
			})
			// })
			this.$bus.$on("changemsg", data => {
				console.log(data, "6666666666")
				this.getCourseList({
					page: 1,
					city: data.cityInfo[1],//城市id
					period: data.classInfo.period,//学段:1=小学,2=初中,3=高中,4=大学
					education_grade_id: data.classInfo.id,//年级id
					education_subject_id: data.subjectInfo[0],//学科id
				})
			})
		},
		methods: {
			async getCourseList(data, index) {
				let res = await getHomeCourse(data)
				// this.tabList[index].childList=res.data.data.data.slice(0, 4)
				console.log(res.data, "99999999999999")
				if (res.data.code == 1) {
					this.tabList[0].childList = res.data.data.lesson_1
					this.tabList[1].childList = res.data.data.lesson_2
					this.tabList[2].childList = res.data.data.lesson_3
					this.tabList[3].childList = res.data.data.lesson_4
				}
			},
			goList(type) { //优课列表
				this.$router.push({
					path: "/fineCourse/courseList",
					query: {
						type
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.leftBg {
		width: 3px;
		height: 17px;
		background: #3478F5;
		border-radius: 0px 2px 2px 0px;
	}
</style>